<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="common/include :: header('添加合同')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-dept-add" th:object="${contract}">
        <input type="hidden" id="filePath" name="appendix">
        <input type="hidden" name="id" th:value="*{id}">
        <div class="col-sm-12">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">客户：</label>
                    <div class="col-sm-8">
                        <select name="customerId" class="form-control" th:field="*{customerId}">
                            <option value="">请选择</option>
                            <option th:each="customer : ${customerList}" th:text="${customer.customerName}"
                                    th:value="${customer.id}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">合同名称：</label>
                    <div class="col-sm-8">
                        <input class="form-control" th:value="*{contractName}" id="contractName" type="text" name="contractName">
                    </div>
                </div>
            </div>
        </div>

        <div class="col-sm-12">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">合同编码：</label>
                    <div class="col-sm-8">
                        <input class="form-control" th:value="*{contractCode}" id="contractCode" type="text" name="contractCode" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">合同金额：</label>
                    <div class="col-sm-8">
                        <input class="form-control" th:value="*{amounts}" id="amounts" type="number" name="amounts" required>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-sm-12">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">开始日期：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input type="text" class=" form-control myTime" th:field="*{startDate}" id="startDate" placeholder="开始日期"
                                   name="startDate"/>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>

                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">结束日期：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input type="text" class=" form-control myTime" th:field="*{endDate}" id="endDate" placeholder="结束日期"
                                   name="endDate"/>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-sm-12">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">电子附加：</label>
                    <div class="col-sm-8">
                        <div id="uploadBtn" class=" fileinput fileinput-new" data-provides="fileinput">
        <span class="btn btn-outline-secondary btn-file">
            <span class="fileinput-new">
                <a class="btn btn-warning btn-sm"><i class="fa fa-upload"></i>&nbsp;上传电子附件</a>
            </span>
            <input type="file" name="file" id="bpmnInfoinition" multiple>
        </span>
                            <span class="fileinput-filename"></span>
                            <a href="#" class="close fileinput-exists" data-dismiss="fileinput" style="float: none">&times;</a>
                        </div>
                    </div>
                </div>


            </div>

        </div>


    </form>
</div>
<th:block th:include="common/include :: footer"/>
<th:block th:include="common/include :: jasny-bootstrap"/>
<link rel="stylesheet" type="text/css" href="/plugins/datetimepicker/jquery.datetimepicker.min.css"/>
<script src="/plugins/datetimepicker/jquery.datetimepicker.full.js"></script>


<script type="text/javascript">
    var prefix = ctx + "/business/contract";
    //表单验证
    $("#form-dept-add").validate({
        onkeyup: false,
        rules: {
            contractName: 'required',  //必填
            contractCode: 'required',  //必填
            amounts: 'required',  //必填
            startDate: 'required',  //必填
            endDate: 'required'  //必填
        },
        messages: {
            contractName: '合同名称不能为空',
            contractCode: '合同编码不能为空',
            amounts: '合同金额不能为空',
            startDate: '开始日期不能为空',
            endDate: '结束日期不能为空'
        },
        focusCleanup: true

    });
    //
    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-dept-add').serialize());
        }
    }
    //文件上传
    $("#bpmnInfoinition").on("change.bs.fileinput", function () {
        var file = $("#bpmnInfoinition")[0].files[0];
        if (!file) {
            $.modal.alertWarning("请上传一个文件");
            return;
        }
        var formData = new FormData();
        formData.append("file", file);
        $.ajax({
            url: prefix + "/uploading",
            type: "post",
            data: formData,
            contentType: false,
            processData: false,
            success: function (result) {
                if (result.code == 0) {
                    $("#filePath").val(result.data);
                } else {
                    $.modal.alertError(result.msg);
                }
            }
        })
    });

    //时间格式
    $('.myTime').datetimepicker({
        format: 'Y-m-d h:i',
        autoclose: true
    });
    $.datetimepicker.setLocale('zh');


</script>
</body>
</html>
